(function(angular) {
  'use strict';
  angular
    .module('fs.waf')
    .config([
      'storageServiceProvider',
      'logEnhancerProvider',
      function(storageServiceProvider, logEnhancerProvider) {
        storageServiceProvider.setLogStorageSize(1000);
        storageServiceProvider.setSearchCriteriaStorageSize(5);
        logEnhancerProvider.logLevels = {
          '*': logEnhancerProvider.LEVEL.OFF
        };
      }
    ])
    .config([
      '$translateProvider',
      function($translateProvider) {
        $translateProvider.useLoader('i18nLoader');
        /*
     * escape: escapes HTML in the translation escapeParameters: escapes HTML in the values of the interpolation parameters sanitize: sanitizes HTML in the translation text using $sanitize
     * sanitizeParameters: sanitizes HTML in the values of the interpolation parameters using $sanitize
     */
        $translateProvider.useSanitizeValueStrategy('escapeParameters');
      }
    ])
    .config([
      '$qProvider',
      function($qProvider) {
        $qProvider.errorOnUnhandledRejections(false);
      }
    ])
    .config([
      '$sceProvider',
      '$sceDelegateProvider',
      function($sceProvider, $sceDelegateProvider) {
        $sceProvider.enabled(true);
        $sceDelegateProvider.resourceUrlWhitelist([
          // Allow same origin resource loads.
          'self',
          // Allow loading from our assets domain. Notice the difference between * and **.
          'blob:**'
        ]);
      }
    ])
    .config([
      '$compileProvider',
      '$httpProvider',
      'ajaxServiceFactoryProvider',
      function($compileProvider, $httpProvider, ajaxServiceFactoryProvider) {
        // ajaxServiceFactoryProvider.setBaseUrl('');
        $httpProvider.useApplyAsync(true);
        $httpProvider.defaults.withCredentials = true;
        $compileProvider.debugInfoEnabled(true);
      }
    ])
    .config([
      'uibDatepickerPopupConfig',
      'uibTimepickerConfig',
      'uibPaginationConfig',
      function(datepickerPopupConfig, uibTimepickerConfig, paginationConfig) {
        datepickerPopupConfig.currentText = 'Biz Date';
        datepickerPopupConfig.clearText = 'Clear';
        datepickerPopupConfig.closeText = 'Close';
        datepickerPopupConfig.datepickerPopupTemplateUrl = 'fs/template/datepickerPopup/popup.html';
        datepickerPopupConfig.datepickerTemplateUrl = 'fs/template/datepicker/datepicker.html';
        uibTimepickerConfig.templateUrl = 'fs/template/timepicker/timepicker.html';
        paginationConfig.previousText = 'Previous';
        paginationConfig.nextText = 'Next';
        paginationConfig.firstText = 'First';
        paginationConfig.lastText = 'Last';
      }
    ])
    .config([
      '$urlRouterProvider',
      '$locationProvider',
      'Constants',
      'routerServiceProvider',
      function($urlRouterProvider, $locationProvider, Constants, routerServiceProvider) {
        // $urlRouterProvider.deferIntercept(true);
        $locationProvider.hashPrefix('');
        routerServiceProvider.setTheme(Constants.THEME_DEFAULT);
      }
    ])
    .config([
      'ChartJsProvider',
      function(ChartJsProvider) {
        ChartJsProvider.setOptions('global', {
          responsive: false
        });
        ChartJsProvider.setOptions('doughnut', {
          cutoutPercentage: 70
        });
        ChartJsProvider.setOptions('global', {
          colors: ['#00589b', '#018ddd', '#43c13f', '#fb8438', '#dcdcdc', '#f7464a', '#4d5360'],
          legend: {
            onClick: function(e, legendItem) {
              e.isLegendClick = true;
              var index = legendItem.datasetIndex;
              var ci = this.chart;
              var meta = ci.getDatasetMeta(index);
              meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
              ci.update();
            },
            labels: {
              boxWidth: 16,
              paddingLeft: 8,
              padding: 8,
              usePointStyle: false,
              generateLabels: function(chart) {
                var data = chart.data,
                  legendItems = [];
                if (!angular.isArray(data.datasets)) {
                  return legendItems;
                }
                angular.forEach(data.datasets, function(dataset, i) {
                  if (!dataset.showInTooltip) {
                    legendItems.push({
                      text: dataset.label,
                      fillStyle: !angular.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0],
                      hidden: !chart.isDatasetVisible(i),
                      lineCap: 'square',
                      lineDash: dataset.borderDash,
                      lineDashOffset: dataset.borderDashOffset,
                      lineJoin: dataset.borderJoinStyle,
                      lineWidth: dataset.borderWidth,
                      strokeStyle: dataset.borderColor,
                      pointStyle: dataset.pointStyle,
                      datasetIndex: i
                    });
                  }
                });
                return legendItems;
              }
            }
          },
          tooltips: {
            enabled: true,
            custom: null,
            mode: 'nearest',
            position: 'average',
            intersect: true,
            backgroundColor: 'rgba(0,0,0,0.7)',
            titleFontStyle: 'bold',
            titleFontSize: 8,
            titleSpacing: 6,
            titleMarginBottom: 6,
            titleFontColor: 'rgba(255,255,255,0.7)',
            titleAlign: 'left',
            bodyFontStyle: 'bold',
            bodyFontSize: 10,
            bodySpacing: 6,
            bodyFontColor: '#fff',
            bodyAlign: 'left',
            footerFontStyle: 'bold',
            footerFontSize: 10,
            footerSpacing: 6,
            footerMarginTop: 6,
            footerFontColor: '#fff',
            footerAlign: 'left',
            yPadding: 6,
            xPadding: 6,
            caretPadding: 6,
            caretSize: 5,
            cornerRadius: 6,
            multiKeyBackground: '#fff',
            displayColors: true,
            borderColor: 'rgba(0,0,0,0.7)',
            borderWidth: 0
          }
        });
        ChartJsProvider.setOptions('bar', {
          scales: {
            xAxes: [
              {
                categoryPercentage: 0.6,
                barPercentage: 0.7
              }
            ]
          }
        });
        ChartJsProvider.setOptions('horizontalBar', {
          scales: {
            xAxes: [
              {
                categoryPercentage: 0.6,
                barPercentage: 0.7
              }
            ]
          }
        });
      }
    ]);
})(angular);
